package service

import "gitee.com/gopher2011/mall/app/dao"

// 全局公开对象
var SmsFlashPromotionProductRelation = smsFlashPromotionProductRelationService{}

// 私有对象，所有的方法都绑定到这个结构体上。

type smsFlashPromotionProductRelationService struct{}

func (p *smsFlashPromotionProductRelationService) Create(arg dao.SmsFlashPromotionProductRelation) (int64, error) {
	res := make([]dao.SmsFlashPromotionProductRelation, 0)
	res = append(res, arg)
	return dao.SmsFlashPromotionProductRelationDao.InsertTemplate(res)
}

func (p *smsFlashPromotionProductRelationService) Update(id int64, u dao.SmsFlashPromotionProductRelation) (int64, error) {
	a := dao.SmsFlashPromotionProductRelation{
		Id:                      id,
		FlashPromotionId:        u.FlashPromotionId,
		FlashPromotionSessionId: u.FlashPromotionSessionId,
		ProductId:               u.ProductId,
		FlashPromotionPrice:     u.FlashPromotionPrice,
		FlashPromotionCount:     u.FlashPromotionCount,
		FlashPromotionLimit:     u.FlashPromotionLimit,
		Sort:                    u.Sort,
	}
	return dao.SmsFlashPromotionProductRelationDao.UpdateTemplate(a)
}

func (p *smsFlashPromotionProductRelationService) Delete(id int64) (int64, error) {
	return dao.SmsFlashPromotionProductRelationDao.DeleteTemplate(id)
}

func (p *smsFlashPromotionProductRelationService) GetItem(id int64) (dao.SmsFlashPromotionProductRelation, error) {
	return dao.SmsFlashPromotionProductRelationDao.SelectTemplate(id)
}

func (p *smsFlashPromotionProductRelationService) List(arg dao.SmsFlashPromotionProductRelationList) ([]dao.SmsFlashPromotionProduct, error) {
	arg.PageNum = (arg.PageNum - 1) * arg.PageSize
	return dao.SmsFlashPromotionProductRelationDao.List(arg)
}

func (p *smsFlashPromotionProductRelationService) GetCount(flashPromotionId, flashPromotionSessionId int64) (int64, error) {
	return dao.SmsFlashPromotionProductRelationDao.GetCount(flashPromotionId, flashPromotionSessionId)
}
